/**
 * @company : 版权所属 四川北星惯牌科技有限公司
 * @contact : 刘经理 19326416371
 **/
 // const res = {
 // 	"code": 1,
 // 	"msg": "请求成功",
 // 	"time": "1741075579",
 // 	"data": {
 // 		"id": 25,
 // 		"qrcode_one": "https:\/\/qrjixing.oss-cn-beijing.aliyuncs.com\/uploads\/20250218\/46aa8b973f537b55ce7f37609663f14c.png",
 // 		"file_path": "\/uploads\/qrcode\/6ee8b72ecedcd382a50f975bd9d1125b.png",
 // 		"verify": "8Moh142f55",
 // 		"qrcode_two": "https:\/\/qrjixing.oss-cn-beijing.aliyuncs.com\/uploads\/20241125\/4a51ae6c7430f641c57d037f3caf99cb.jpg",
 // 		"qrcode_three": "",
 // 		"background": "https:\/\/qrjixing.oss-cn-beijing.aliyuncs.com\/uploads\/20250225\/04f3919c9f51a65df7e632db43e3b841.jpg",
 // 		"origin": 1,
 // 		"access_num": 11,
 // 		"create_time": 1739866226,
 // 		"update_time": 1740469663,
 // 		"extend": [],
 // 		"create_time_text": "2025-02-18 16:10:26",
 // 		"update_time_text": "2025-02-25 15:47:43"
 // 	}
 // }
// 全局请求封装
// const developmentUrl = 'https://groupdev.jixingge.com';
const productionUrl = 'https://qr.jixingge.com';

// var baseUrl = process.env.NODE_ENV === 'development' ? developmentUrl : productionUrl;
// var baseUrl = process.env.NODE_ENV === 'development' ? 'https://groupdev.jixingge.com' : 'https://gapi.jixingge.com';
// var baseUrl =  '/api' 
var baseUrl = 'https://qr.jixingge.com/api';
// var baseUrl = 'https://groupdev.jixingge.com';
// console.log('process.env.NODE_ENV', process.env.NODE_ENV);
// 需要修改token，和根据实际修改请求头
const request = (url, method, params, loading = false) => {
	uni.getNetworkType({
		success: function(res) {
			if (res.networkType === "none") {
				// console.log("当前无网络");
				uni.showToast({
					title: '请检查网络连接',
					icon: 'none'
				})
			} else {}
		}
	});
	// 获取本地token
	const tokens = uni.getStorageSync('user_token');
	//判断进入页面的时候或者本地有没有token,有就直接值某一页，没有则请求接口
	if (loading) {
		uni.showLoading({
			title: "加载中"
		});
	}

	// 根据请求方法或URL来判断是否添加请求头
	var header = {}
	if (method == "post") {
		header['content-type'] = "application/json";
		// header['content-type'] = "application/x-www-form-urlencoded";
		header['token'] = tokens;
	} else {
		header['content-type'] = "application/json";
		header['token'] = tokens;
	}
	return new Promise((resolve, reject) => {
		uni.request({
			url: baseUrl + url,
			method: method,
			header: header,
			data: params,
			success(response) {
				const res = response;
				if (res.statusCode == 401) {
					const userStore = userInfoStore();
					uni.showToast({
						title: '登录失效，请重新登录',
						icon: 'none'
					});
					uni.removeStorageSync('user_token');
					setTimeout(() => {
					}, 1200)
					return
				}

				resolve(res.data);
			},
			fail(err) {
				reject(err);
			},
			complete(a) {
				if (loading) {
					setTimeout(() => {
						uni.hideLoading();
					}, 600)
				}
			}
		});
	}).catch((e) => {});
};
export default request;